
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 03/04/2016 19:21:24
-- Generated from EDMX file: D:\thoma\Documents\Visual Studio 2015\Projects\serietheque\Sériethèque\SeriesModelEntity.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [bdd];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_dbo_Episodes_dbo_Saisons_SaisonsID]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Episodes] DROP CONSTRAINT [FK_dbo_Episodes_dbo_Saisons_SaisonsID];
GO
IF OBJECT_ID(N'[dbo].[FK_dbo_Saisons_dbo_Series_SeriesID]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Saisons] DROP CONSTRAINT [FK_dbo_Saisons_dbo_Series_SeriesID];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Episodes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Episodes];
GO
IF OBJECT_ID(N'[dbo].[Saisons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Saisons];
GO
IF OBJECT_ID(N'[dbo].[Series]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Series];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Episodes'
CREATE TABLE [dbo].[Episodes] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IdTvdb] int  NULL,
    [Name] nvarchar(max)  NULL,
    [Num] int  NOT NULL,
    [AirDate] datetime  NULL,
    [AddDate] datetime  NULL,
    [Overview] nvarchar(max)  NULL,
    [FileName] nvarchar(max)  NULL,
    [FilePath] nvarchar(max)  NULL,
    [Saw] bit  NULL,
    [Sub] bit  NULL,
    [SubPath] nvarchar(max)  NULL,
    [SaisonsID] int  NOT NULL,
    [Taille] float  NULL
);
GO

-- Creating table 'Saisons'
CREATE TABLE [dbo].[Saisons] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IdTvdb] int  NULL,
    [Num] int  NOT NULL,
    [Path] nvarchar(max)  NULL,
    [SeriesID] int  NOT NULL,
    [Name] nvarchar(max)  NULL
);
GO

-- Creating table 'Series'
CREATE TABLE [dbo].[Series] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IdTvdb] int  NULL,
    [Name] nvarchar(max)  NULL,
    [Live] nvarchar(max)  NULL,
    [AirDay] nvarchar(max)  NULL,
    [Overview] nvarchar(max)  NULL,
    [ImagePath] nvarchar(max)  NULL,
    [Path] nvarchar(max)  NULL,
    [Followed] bit  NOT NULL,
    [TorrentNames] nvarchar(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Episodes'
ALTER TABLE [dbo].[Episodes]
ADD CONSTRAINT [PK_Episodes]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Saisons'
ALTER TABLE [dbo].[Saisons]
ADD CONSTRAINT [PK_Saisons]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Series'
ALTER TABLE [dbo].[Series]
ADD CONSTRAINT [PK_Series]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [SaisonsID] in table 'Episodes'
ALTER TABLE [dbo].[Episodes]
ADD CONSTRAINT [FK_dbo_Episodes_dbo_Saisons_SaisonsID]
    FOREIGN KEY ([SaisonsID])
    REFERENCES [dbo].[Saisons]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_Episodes_dbo_Saisons_SaisonsID'
CREATE INDEX [IX_FK_dbo_Episodes_dbo_Saisons_SaisonsID]
ON [dbo].[Episodes]
    ([SaisonsID]);
GO

-- Creating foreign key on [SeriesID] in table 'Saisons'
ALTER TABLE [dbo].[Saisons]
ADD CONSTRAINT [FK_dbo_Saisons_dbo_Series_SeriesID]
    FOREIGN KEY ([SeriesID])
    REFERENCES [dbo].[Series]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_Saisons_dbo_Series_SeriesID'
CREATE INDEX [IX_FK_dbo_Saisons_dbo_Series_SeriesID]
ON [dbo].[Saisons]
    ([SeriesID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------